package 狂神.GUI;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @ClassName: Testpanel
 * @Auther: Drawin
 * @Date: 2021/12/22 22:05
 * @Description:
 */

public class Testpanel {
    public static void main(String[] args) {
        Frame frame = new Frame();
        Panel panel = new Panel();

        frame.setLayout(null);//设置布局

        frame.setBounds(300,300,500,500);//坐标
        frame.setBackground(new Color(102, 204, 255));

        panel.setBounds(50,50,200,200);//panel设置坐标，相对于frame
        panel.setBackground(new Color(238, 0, 0));

        frame.add(panel);
        frame.setVisible(true);

        //监听窗口关闭事件，system.exit(0)
        //适配器模式：
        frame.addWindowListener(new WindowAdapter() {
            //点击关闭按钮时做的事——结束程序
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }
}
